package apis.amapv2.com.searchview;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class Test0Activity extends AppCompatActivity{

    private static final String TAG = Test0Activity.class.getSimpleName();
    private Context mContext;
    private SearchView mSearchView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test0);

        initParamsAndValues();

        initView();
    }

    private void initParamsAndValues() {
        mContext = this;
    }

    private void initView() {
        mSearchView = findViewById(R.id.search_view);
    }

    public void test1(View view) {
        Toast.makeText(mContext, "test1", Toast.LENGTH_SHORT).show();
        //判断SearchView是否展开，如果展开了，就关闭，如果没有展开，就展开
        if (mSearchView.isIconified()){
            mSearchView.setIconified(false);
            Toast.makeText(mContext, "展开", Toast.LENGTH_SHORT).show();
        } else {
            mSearchView.setIconified(true);
            Toast.makeText(mContext, "关闭", Toast.LENGTH_SHORT).show();
        }
    }

    public void test2(View view) {
        Toast.makeText(mContext, "修改这个Activity对应的Style!", Toast.LENGTH_SHORT).show();
    }

    public void test3(View view) {
        Toast.makeText(mContext, "test3", Toast.LENGTH_SHORT).show();
        mSearchView.setIconified(false);//设置searchView处于展开状态
        mSearchView.onActionViewExpanded();// 当展开无输入内容的时候，没有关闭的图标
    }

    public void test4(View view) {
        mSearchView.setIconified(false);//设置searchView处于展开状态
        mSearchView.onActionViewCollapsed();//当展开无输入内容的时候，有关闭的图标
    }

    public void test5(View view) {
        mSearchView.setIconified(false);//设置searchView处于展开状态
        mSearchView.onActionViewExpanded();// 当展开无输入内容的时候，没有关闭的图标
        mSearchView.setIconifiedByDefault(false);//默认为true在框内，设置false则在框外
    }

    public void test6(View view) {
        Toast.makeText(mContext, "test6", Toast.LENGTH_SHORT).show();
        mSearchView.setSubmitButtonEnabled(true);//显示提交按钮
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            //当点击提交按钮的时候执行的方法
            @Override
            public boolean onQueryTextSubmit(String query) {
                //提交按钮的点击事件
                Toast.makeText(mContext, query, Toast.LENGTH_SHORT).show();
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                //当输入框内容改变的时候回调
                Log.e(TAG,"内容: " + newText);
                return true;
            }
        });
    }

    public void test7(View view) {
        Toast.makeText(mContext, "test7", Toast.LENGTH_SHORT).show();
        mSearchView.setQueryHint("输入歌曲名查找");
    }

    public void test8(View view) {
        Toast.makeText(mContext, "在这个Activity对应的style设置了", Toast.LENGTH_SHORT).show();
    }

    public void test9(View view) {
        SearchView.SearchAutoComplete mSearchAutoComplete = mSearchView.findViewById(R.id.search_src_text);
        //设置输入框提示文字样式
        mSearchAutoComplete.setHintTextColor(getResources().getColor(android.R.color.white));//设置提示文字颜色
        mSearchAutoComplete.setTextColor(getResources().getColor(android.R.color.white));//设置内容文字颜色
    }

    public void test10(View view) {
        Toast.makeText(mContext, "在styles.xml中有设置", Toast.LENGTH_SHORT).show();
    }
}
